package wtws.manager.in;

import java.io.File;
import java.util.Queue;

import wtws.manager.in.interf.MessageReader;
import wtws.message.UnknownMessage;
import wtws.message.interf.TdwrProdMessage;
import wtws.util.JobConfig;

public class UnknownMessageReader extends MessageReader {

	public UnknownMessageReader() {

	}

	public UnknownMessageReader(Queue<TdwrProdMessage> q, JobConfig jobConfig) {
		super(q, jobConfig);
	}

	@Override
	public void run() {
		while (true) {
			getFiles();
			try {
				Thread.sleep(jobConfig.getInFreq());
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	@Override
	public void getFiles() {

		File lrDir = new File(jobConfig.getMsgInDir());
		File[] lrFiles = lrDir.listFiles();
		for (File file : lrFiles) {
			q.offer(new UnknownMessage(file));
			file.delete();
		}
	}

}
